package com.zzy.sqlSession;

import com.zzy.config.XMLConfigBuilder;
import com.zzy.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * 文件描述: <br>
 * 版权所有: Copyright (c) 2021/5/1<br>
 * 完成日期: 2021/5/1<br>
 *
 * @author zainzhang
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream in) throws DocumentException, PropertyVetoException, ClassNotFoundException {
        // 1.使用dom4j解析配置文件，将解析出来的内容封装到Configuration中
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(in);

        // 2. 创建SqlSessionFactory对象
        return new DefaultSqlSessionFactory(configuration);
    }
}
